using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class RegexPage : System.Web.UI.Page
{
    TextBox textBox;
    Label label;
    protected void Page_Load(object sender, EventArgs e)
    {
        label = new Label();
        label.Text = "Your phone:";
        this.form1.Controls.Add(label);
        textBox = new TextBox();
        textBox.ID = "Phone";
        this.form1.Controls.Add(textBox);
        label = new Label();
       
        this.form1.Controls.Add(label);
        Button button = new Button();
        button.Text = "OK";
        button.Click += new EventHandler(button_Click);
        this.form1.Controls.Add(button);        
        
    }

    void button_Click(object sender, EventArgs e)
    {
        if (!IsEmail(textBox.Text))
        {           
            label.Text = "Invalid email";
        }
    }
    bool IsEmail(string email)
    {
        if (email == null | email.Length > 100) return false;
        string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
            @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
            @".)+))([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$";
        Regex re = new Regex(strRegex);
        return (re.IsMatch(email));
    }
}
